package thread.JUC;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class LearnCallable {
    static class MyCallable implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            int result = 0;
            for (int i = 1; i <= 1000; i++) {
                result += i;
            }
            return result;
        }
    }
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> myCallable = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask<>(myCallable);
        Thread t = new Thread(futureTask);
        t.start();
        int result = futureTask.get();
        System.out.println(result);
    }
}
